package com.zcl.Thread.useThread;

/**
 * @Description:
 * @author: zcl
 * @date: 2022/3/9  12:36
 */
public class LoginServlet {
    private static String usernameRef;

    private static String passwordRef;

    synchronized public static void doPost(String username, String password){
        try {
            usernameRef = username;
            if (username.equals("a")) {
                Thread.sleep(5000);
            }
            passwordRef = password;
            System.out.println("username= "+ usernameRef+ " password= "+passwordRef);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}


class ALogin extends Thread{

    @Override
    public void run(){
        LoginServlet.doPost("a", "aa");
    }
}

class BLogin extends Thread{

    @Override
    public void run(){
        LoginServlet.doPost("b", "bb");
    }
}

class run {
    public static void main(String[] args) {
        ALogin aLogin = new ALogin();
        aLogin.start();
        BLogin bLogin = new BLogin();
        bLogin.start();

    }
}